'''
通俗一点说，每隔k个反转k个，末尾不够k个时全部反转；
'''
class Solution:
    def reverseStr(self, s: str, k: int) -> str:
        left, mid, right = 0, k, 2 * k                  # 初始化左中右指针
        res = ''                                        # 初始化结果字符串
        while len(res) < len(s):                        # 满足条件时执行
            res += s[left:mid][::-1] + s[mid:right]     # 把当前单元的结果添加到结果字符串
            left, mid, right = left + 2 * k, mid + 2 * k, right + 2 * k
        return res
'''
超出范围的[]是空串。
'''
class Solution:
    def reverseStr(self, s: str, k: int) -> str:
        l,m,r = 0,k,2*k
        res = ''
        while len(res) < len(s):
            res += s[l:m][::-1] + s[m:r]
            l,m,r = l + 2*k,m+2*k,r+2*k
        return res

'''
转成list，然后i到i+k的时候反转一下
'''
class Solution:
    def reverseStr(self, s: str, k: int) -> str:
        a = list(s)
        for i in range(0, len(a), 2*k):
            a[i:i+k] = a[i:i+k][::-1]
        return "".join(a)
print('123','123'[2:5])